<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="applicable-device" content="pc">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="icon" href="/icon.png" />
    <link rel="stylesheet" href="/static/index/css/reset.css">
    <link rel="stylesheet" href="/static/index/lib/bootstrap.css">
    <link rel="stylesheet" href="/static/index/css/common.css">
    <link rel="stylesheet" href="/static/index/css/home.css">
    <link rel="stylesheet" href="/static/index/css/users.css">
    <script src="/static/index/lib/jquery-2.1.4.js"></script>
    <script src="/static/index/lib/bootstrap.min.js"></script>
    <script type="text/javascript" src="/static/index/lib/template.js"></script>
    <script>
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?8b340ebdd740974de9d621b14ab09b43";
              var s = document.getElementsByTagName("script")[0]; 
              s.parentNode.insertBefore(hm, s);
            })();
        </script>
</head>

<body>
    {include file="public/push"}
    {include file="public/usersHeader"}
    <div class="widthFullScreen">
        <div class="wdSafe user_body clearfix">
            {include file="public/usersLeftNav"}
            <!-- left over -->
            <div class="pull-right right_wrap">
                <div class="nav_common border-top">
                    <ol class="breadcrumb pull-left">
                        <li><a href="/users/index">用户中心</a></li>
                        <li><a href="/users/companyTeam">我的资料</a></li>
                        <li><a href="/users/companyTeam">经营团队</a></li>
                        <li class="active">添加团队</li>
                    </ol>
                </div>
                <div class="comUser_wrap">
                    <div class="form-horizontal">
                        <form method="post" id="zhizhiaoForm" enctype="multipart/form-data">
                            <div class="form-group">
                                <label for="" class="col-sm-2 control-label">
                                    <span class="colorRed">*</span>&nbsp;&nbsp;个人照片
                                </label>
                                <div class="col-sm-7">
                                    <div class="imgWrap_upload">
                                        <div class="upLoadImg_style">
                                            <img id="logoPic" src="https://img.qikuai100.com/bg.png" />
                                            <input type="file" name="file" id="logoIpt" accept="image/*" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名
                            </label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control ipt_styleSub" name="" placeholder="请输入联系人姓名" id="name" value="" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;联系电话
                            </label>
                            <div class="col-sm-10">
                                <input type="number" class="form-control ipt_styleSub" name="" placeholder="请输入联系电话" id="phoneNum" value="" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="one" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;个人经验
                            </label>
                            <div class="col-sm-10">
                                <textarea class="form-control textarea_style" placeholder="请详细填写个人经验" name="" rows="" cols="" id="experience"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="two" class="col-sm-2 control-label">
                                <span class="colorRed">*</span>&nbsp;&nbsp;是否显示
                            </label>
                            <div class="col-sm-10" id="chooseHidden">
                                <label class="radio-inline">
                                   <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="1">显示
                                </label>
                                <label class="radio-inline">
                                  <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="0">隐藏
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <div class="submitBtn" onclick="initDate()">保存</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- right over -->
        </div>
    </div>
    <div class="widthFullScreen heightGray"></div>
    {include file="public/footer"}

    <script type="text/javascript" src="/static/index/layer/layer.js"></script>
    <script type="text/javascript">
        var baseUrl = 'https://api.qikuai100.com/',
            uid = localStorage.getItem("uid");

        $(function() {
            /**
            * 上传照片
            */
            var uploadingLogo = false;
            $("#logoIpt").on("change", function() {
                if (uploadingLogo) {
                    layer.msg("文件正在上传中，请稍候");
                    return false;
                }
                var indexLogo = layer.load(1, {shade: false});
                $.ajax({
                    url: baseUrl + "api/img/upload",
                    type: 'POST',
                    cache: false,
                    data: new FormData($('#zhizhiaoForm')[0]),
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    beforeSend: function() {
                        uploadingLogo = true;
                    },
                    success: function(data) {
                        layer.close(indexLogo);
                        console.log(data);
                        if (data.ret == 0) {
                            $("#logoPic").attr("src", data.data.url);
                        } else {
                            layer.msg("上传logo失败");
                        }
                        uploadingLogo = false;
                    }
                });
            });
        });

        /**
         * 初始化数据
         */
        function initDate() {
             var is_hidden = 1;
            $('#chooseHidden').find("input").each(function(i,item){
                if($(this).prop("checked")){
                    is_hidden = $(this).val();
                }
            });
            var name = $('#name').val(),
                phone = $("#phoneNum").val(),
                avatar = $('#logoPic').attr("src"),
                experience = $('#experience').val();
            var result = isPhoneNum();
            if($.trim(avatar) == 'https://img.qikuai100.com/bg.png' || $.trim(avatar) == ''){
                layer.msg("请上传个人照片");
                return;
            }
            if($.trim(name) == ''){
                layer.msg("请输入姓名");
                return;
            }
            if(result == false){
                layer.msg("请输入正确的手机号码");
                return;
            }
            if($.trim(experience) == ''){
                layer.msg("请输入从业经验");
                return;
            }
            $.ajax({
                type: "POST",
                url: baseUrl + "api/staff/add",
                data: {
                    uid: uid,
                    phone: phone,
                    name: name,
                    avatar: avatar,
                    experience: experience,
                    is_hidden: is_hidden
                },
                success: function(result) {
                    console.log(result);
                    if (result.ret == 0) {    
                        layer.msg("添加成功");             
                        setTimeout(function(){
                            window.location.href = '/users/companyTeam';
                        }, 1000);
                    } else {
                        layer.msg(result.res_info);
                    }
                }
            });
        };

        //校验手机号是否合法
        function isPhoneNum() {
            var phone_1 = $("#phoneNum").val();
            var myreg = /^1[34578]\d{9}$/;
            if(!myreg.test(phone_1)) {
                layer.msg("请输入有效的手机号码");
                return false;
            } else {
                return true;
            }
        }
    </script>
</body>

</html>